<?php
require_once ('library/Controller/IController.php');
require_once ('library/Controller/BaseController.php');

/**
 *
 * @author Nguyen
 *        
 */
class TripController extends BaseController implements IController {
	public $trip;
	public $result;
	/**
	 * hien thi nhung trip chua chay
	 * $trip  : khoi tao tripModel
	 * $result : list nhung trip chua chay
	 */
	public function waitTripAction()
	{	
		$this->trip = new Trip();
		$this->result = $this->trip->waitTrip();
		iDebug::debugArray($this->result);
	}
	
	public function listAction(){
		$this->view()->setHasLayout(false);
		$result = array();
		$trip = new Trip();
 		$result = $this->trip->getListTripPrepare();
 		$this->view()->jsonResult = $result;
	}
	/* (non-PHPdoc)
	 * @see BaseController::editAction()
	 */
	public function editAction() {
		// TODO Auto-generated method stub
		$route= new Route();
		$this->view ()->relativeData = $route->getNameRoute();
		$car = new Car();
		$this->view()->cardata = $car->getAllnumberplate();
		$driver = new Driver();
		$this->view()->driverdata = $driver->getNameDriver();
		
		if ($this->isPost ()) {
			$entity = $this->getEntityData ();
			iDebug::debugArray ( $entity );
			switch ($this->_actionType) {
				case 'insert' :
					echo 'insert';
					$this->view ()->objectData = $this->_model->insert ( $entity );
					break;
				case 'update' :
					echo 'update';
					$this->view ()->objectData = $this->_model->update ( $entity );
					break;
			}
			$this->_redirect ( '?_module=' . $this->_context . '&_action=getall' );
		} else {
			$id = $this->_model->getId ();
			$entity = array ();
			foreach ( $id as $value ) {
				$param = '_' . $this->_context . $value;
				if ($this->getParram ( $param, '' ) != '')
					$entity [$value] = $this->getParram ( $param, '' );
			}
			if (count ( $entity ) > 0) {
				$this->view ()->objectData = $this->_model->getbyid ( $entity );
				$this->view ()->title = Resource::getResource('edit') ." ".Resource::getResource($this->_context) ;
			}
			if (count ( $entity ) == 0) {
				$this->view ()->title = Resource::getResource('insert') ." ".Resource::getResource($this->_context) ;
			}
		}
	}

	
}

?>